// 设置一个初始数据
let obj = [
    {
        person : "zml",
        password:111
    },
    {
        person : "zml1",
        password:1111
    },
    {
        person : "zml2",
        password:11111
    }
]

// 引入模块
let fs=require("fs")
let path=require("path")
let express = require("express")

let app = express();
// 设置获取数据的类型
app.use(express.urlencoded({ extended:false}))
// 设置路由
app.get("/login", (req, res) => { 
    let url = path.join(__dirname , "/login.html")
    
    let data = fs.readFileSync(url)
    
    res.end(data)

})

// 获取表单提取的数据
app.post("/login", (req, res) => { 
    let tag=obj.find((item) => { 
        return item.person == req.body.zhanghao && item.password == req.body.pass;  
    })

    if (tag) {
        res.end("1")
    } else { 
        res.end("2")
    }
    
})

// 监听端口

app.listen(3000, "127.0.0.1", () => { 
    console.log(1);
})